package com.viking.XFT;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import java.lang.reflect.Field;

public class FloatService extends Service {
    private FloatManager fm = null;

    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        fm.removeFloat();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        fm.addFloat();
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        fm = FloatManager.getInstance(getApplicationContext());
        fm.setStatusBarHeight(getStatusBarHeight());
    }

    private int status_bar_height = 0;
    private int getStatusBarHeight() {
        if (status_bar_height == 0) {
            try {
                Class<?> c = Class.forName("com.android.internal.R$dimen");
                Object o = c.newInstance();
                Field field = c.getField("status_bar_height");
                int x = (Integer) field.get(o);
                status_bar_height = getResources().getDimensionPixelSize(x);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        //Log.d("FloatService", String.format("%d", status_bar_height));
        return status_bar_height;
    }

}
